<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取用户通讯录</title>
</head>
<body>
<button onclick="getContacts()">获取通讯录</button>
<a href="/admin/phone?pid="></a>
<ul id="contactsList"></ul>

<script>
    // function getContacts() {
    //     if (navigator.contacts && navigator.contacts.select) {
    //         var options = new ContactFindOptions();
    //         options.multiple = true;
    //         var fields = ['displayName', 'name', 'emails', 'phoneNumbers'];
    //
    //         navigator.contacts.select(fields, function(contacts) {
    //             var contactsList = document.getElementById('contactsList');
    //             contactsList.innerHTML = '';
    //             contacts.forEach(function(contact) {
    //                 var displayName = contact.displayName || '';
    //                 var email = contact.emails && contact.emails.length > 0 ? contact.emails[0].value : '';
    //                 var phoneNumber = contact.phoneNumbers && contact.phoneNumbers.length > 0 ? contact.phoneNumbers[0].value : '';
    //                 contactsList.innerHTML += '<li>Name: ' + displayName + ', Email: ' + email + ', Phone: ' + phoneNumber + '</li>';
    //             });
    //         }, function(error) {
    //             console.error('Error retrieving contacts: ', error);
    //         }, options);
    //     } else {
    //         alert('浏览器不支持获取通讯录功能');
    //     }
    // }
    function getContacts(){
        if ('contacts' in navigator) {
            navigator.contacts.getAll(function (contacts) {
                console.log(contacts)
                // 处理contacts数组
            }, function (error) {
                console.log('获取通讯录失败：', error);
            });
        } else {
            console.log('不支持获取手机通讯录');
        }
    }

</script>

<script src="cordova.js"></script>
</body>
</html>
